<template>
    <el-dialog title="供应商信息" :visible.sync="dialogFormVisible" width="35%" :append-to-body="true"
    @close="dialogClose">
      <el-form status-icon label-width="100px">
          <el-form-item label="供应商编号">
              <el-input v-model="provinfo.fpid" type="text" autocomplete="off" />
          </el-form-item>
          <el-form-item label="供应商名称">
              <el-input v-model="provinfo.fpname" type="text" autocomplete="off" />
          </el-form-item>
          <el-form-item label="联系人">
            <el-input v-model="provinfo.fpcontacts" type="text" autocomplete="off" />
          </el-form-item>
          <el-form-item label="联系电话">
              <el-input v-model="provinfo.fptel" type="text" autocomplete="off" />
          </el-form-item>
          <el-form-item label="传真">
              <el-input v-model="provinfo.fpfax" type="text" autocomplete="off" />
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="provinfo.fpemail" type="text" autocomplete="off" />
          </el-form-item>
          <el-form-item label="地址">
            <el-input v-model="provinfo.fpaddr" type="textarea" autocomplete="off" />
          </el-form-item>
          <el-form-item label="备注">
              <el-input v-model="provinfo.fpmemo" type="textarea" placeholder="请输入内容" maxlength="200"
              show-word-limit  size="medium" autocomplete="off" />
          </el-form-item>
          <el-form-item>
              <el-button type="primary" @click="submitForm(provinfo)">提交</el-button>
              <el-button @click="resetForm">重置</el-button>
          </el-form-item>
      </el-form>
    </el-dialog>
</template>
<script>
import { createProv, updateProv } from '@/api/prov'

export default {
    props: {
        dialogFormVisible: Boolean,
        editProvInfo: {
            type:Array,
            default: []
        },
        updateOrCreate: Boolean
    },
    data() {
        return {
            provinfo: {}
        }
    },
    updated () {
        this.provinfo = this.editProvInfo
    },
    methods: {
        submitForm(provinfo) {
            if (this.updateOrCreate) {
                updateProv(provinfo).then(response => {
                    this.$message.success('修改供应商信息成功')
                    this.$parent.fetchData()
                })
                this.dialogClose()
            } else {
                createProv(provinfo).then(response => {
                    this.$message.success('创供应商信息成功')
                    this.$parent.fetchData()     
                })
                this.dialogClose()
            }
        },
        resetForm() {
            this.provinfo = {}
        },
        // 解决父页面按钮只能点击一次问题
        dialogClose() {
            this.dialogFormVisible = false
            this.$parent.vueReset()
        }
    }
}
</script>
    